package jmu.service.impl;

import jmu.dao.StudentsDAO;
import jmu.service.StudentsService;
import jmu.vo.Students;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentsServiceImpl implements StudentsService {
    @Autowired
    private StudentsDAO studentsDAO;
    @Override
    public List<Students> findAllStudents() throws Exception {
        return this.studentsDAO.findAllStudents();
    }

    @Override
    public List<Students> getStudentsLike(String keywords) throws Exception {
        return this.studentsDAO.getStudentsLike(keywords);
    }

    @Override
    public Students isValidUser(String studentId, String password) {
        Students student = null;
        try {
            student = studentsDAO.findStudentsByStudentId(studentId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // 先检查用户是否存在，再验证密码是否匹配
        if (student != null && password.equals(student.getStudentPwd())) {
            return student;
        }
        return null;
    }
}
